package cn.shengchao.dubbo;

import cn.dev33.satoken.same.SaSameUtil;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;



/**
 * Sa-Token 整合 Dubbo Provider端过滤器
 */
@Activate(group = {CommonConstants.PROVIDER}, order = -10000)
public class SameTokenDubboProviderFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        // 取出 Same-Token 进行校验
        String sameToken = invocation.getAttachment(SaSameUtil.SAME_TOKEN);
        System.out.println("SameTokenDubboProviderFilter"+sameToken);
        if (sameToken != null){
            SaSameUtil.checkToken(sameToken);
        }else {
            System.err.println("SAME_TOKEN null");
        }
        // 开始调用
        return invoker.invoke(invocation);
    }

}